﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using DataGridViewAutoFilter;
using ProrabHelp.Library;

namespace ProrabHelp.UI
{
    public partial class IncomProductInputForm : Form
    {
        ServerObject mServerObject = null;

        public IncomProductInputForm()
        {
            InitializeComponent();
            mServerObject = new ServerObject();
        }

        private void FillProductsGridView()
        {
            BindingSource bindigSource = new BindingSource(mServerObject.GetProductList(), null);
            productsGridView.DataSource = bindigSource;

            if (productsGridView.DataSource != null)
            {
                foreach (DataGridViewColumn col in productsGridView.Columns)
                {
                    col.HeaderCell = new DataGridViewAutoFilterColumnHeaderCell(col.HeaderCell);
                }

                productsGridView.AutoResizeColumns();
            }
        }

        private void FillCompanyListGridView(int productID)
        {
            BindingSource bindigSource = new BindingSource(mServerObject.GetCompanyListPrestedProduct(productID), null);
            productsGridView.DataSource = bindigSource;

            if (productsGridView.DataSource != null)
            {
                foreach (DataGridViewColumn col in productsGridView.Columns)
                {
                    col.HeaderCell = new DataGridViewAutoFilterColumnHeaderCell(col.HeaderCell);
                }

                productsGridView.AutoResizeColumns();
            }
        }

        private void productsGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (productsGridView.SelectedRows.Count == 1 )
            {
                int producID = 0;
                int.TryParse(productsGridView.Rows[productsGridView.SelectedRows[0].Index].Cells["id"].Value.ToString(), out producID);
                if (producID != 0) FillCompanyListGridView(producID);
            }
            
        }


    }
}
